package com.memory.monitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.memory.monitor.annotation.AuthCheck;
import com.memory.monitor.annotation.LogInformation;
import com.memory.monitor.common.BaseResponse;
import com.memory.monitor.common.DeleteRequest;
import com.memory.monitor.common.ResultUtils;
import com.memory.monitor.constant.UserConstant;
import com.memory.monitor.model.dto.area.AreaAddRequest;
import com.memory.monitor.model.dto.area.AreaQuerryRequest;
import com.memory.monitor.model.dto.area.AreaUpdateRequest;
import com.memory.monitor.model.entity.Area;
import com.memory.monitor.service.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/area")
@Slf4j
public class AreaController {
    @Resource
    private AreaService areaService;

    /**
     * 分页获取地区列表
     *
     * @param areaQuerryRequest

     * @return
     */
    @PostMapping("/list/page")
    // @LogInformation
    public BaseResponse<Page<Area>> listByPageArea(@RequestBody AreaQuerryRequest areaQuerryRequest) {
        long current = areaQuerryRequest.getCurrent();
        long size = areaQuerryRequest.getPageSize();
        // Page<User> userPage = userService.page(new Page<>(current, size),
        //         userService.getQueryWrapper(userQueryRequest));
        Page<Area> areaPage = areaService.page(new Page<>(current, size));

        return ResultUtils.success(areaPage);
    }

    /**
     * 增加地区信息 返回地区id
     *
     * @param areaAddRequest

     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Long> addArea(@RequestBody AreaAddRequest areaAddRequest){
        Long id = areaService.addArea(areaAddRequest);
        return ResultUtils.success(id);
    }

    /**
     * 修改地区信息 返回boolean
     *
     * @param areaUpdateRequest

     * @return
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateArea(@RequestBody AreaUpdateRequest areaUpdateRequest){
      Boolean result= areaService.updateArea(areaUpdateRequest);
        return ResultUtils.success(result);
    }

    /**
     * 删除地区信息 返回boolean
     *
     * @param deleteRequest

     * @return
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteArea(@RequestBody DeleteRequest deleteRequest){
        Boolean result = areaService.deleteArea(deleteRequest);
        return ResultUtils.success(result);
    }
}